package ercahshu

func buildTree1(preorder []int, inorder []int) *TreeNode {
	if len(preorder) == 0 {
		return nil
	}
	top := preorder[0]
	gen := getMid(inorder, top)
	root := &TreeNode{Val: top}
	root.Left = buildTree1(preorder[1:gen+1], inorder[:gen])
	root.Right = buildTree1(preorder[gen+1:], inorder[gen+1:])
	return root
}
